package com.imooc.coupon.controller;

import com.imooc.coupon.annotation.IgnoreResonseAdvice;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * @Author Administrator
 * @Date 2021/11/15 20:14
 * @Version 1.0
 */
@Controller
public class RibbonController {

    @Autowired
    private RestTemplate restTemplate;//可以访问其他服务


    /**
     * 通过ribbon调用模板微服务
     * @return
     */
    @GetMapping("/info")
    @IgnoreResonseAdvice//不需要被统一包装，忽略
    public TemplateInfo getTemplateInfo(){
        String infoUrl = "http://eureka-client-coupon-template/coupon-template/info";
        return restTemplate.getForEntity(infoUrl, TemplateInfo.class).getBody();
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    private static class TemplateInfo{
        private Integer code;
        private String message;
        private List<Map<String, Object>> data;

    }

}
